package com.yanqu.road.server.gameplayer.module.activity.tomb.service;

import com.google.protobuf.InvalidProtocolBufferException;
import com.yanqu.road.pb.syncMessage.SyncMessage;
import com.yanqu.road.pb.tomb.Tomb;
import com.yanqu.road.server.game.service.IGameServiceCommand;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.tomb.TombModule;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.sync.message.SyncResponse;

public class TombUserUnderAttackPushServiceCmd implements IGameServiceCommand {

    @Override
    public SyncResponse execute(SyncMessage.Request request) throws InvalidProtocolBufferException {
        SyncResponse syncResponse = new SyncResponse();
        Tomb.TombUserUnderAttackPush resp = Tomb.TombUserUnderAttackPush.parseFrom(request.getDataBytes());
        GamePlayer onlinePlayer = GamePlayerMgr.getOnlinePlayer(resp.getUserId());
        if (onlinePlayer != null) {
            onlinePlayer.getModule(TombModule.class).updateUnionRank(resp.getUnionScore());
            onlinePlayer.sendPacket(ClientProtocol.U_TOMB_USER_UNDER_ATTACK_PUSH, resp.toBuilder());
        }
        return syncResponse;
    }
}
